<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category CollectArticle.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/10/28  20:44
 * +--------------------------------------------------------+
 */

namespace App\Models;


use App\Exceptions\ResponseException;

class CollectArticle extends BaseModel
{
    protected $table = "collect_article";
    /**
     * 可以被批量赋值的属性.
     *
     * @var array
     */
    protected $fillable = [ 'id', 'title', 'href', 'source', 'created_at', 'updated_at' ];

    static public function getList($params)
    {
        $query   = self::query();
        $perPage = empty($params['perPage']) ? 10 : $params['perPage'];

        if (!empty($params['field']) && !empty($params['order'])) {
            $query = $query->orderBy($params['field'], $params['order']);
        }


        $list = $query->orderBy('id', 'desc')->paginate($perPage)->toArray();

        return return_success_msg(ResponseException::REQUEST_SUCCESS_MESSAGE, $list);
    }

    static public function getNumber()
    {
        $all_num    = self::query()->count();
        $hx_number  = self::query()->where('source', 1)->count();
        $k36_number = self::query()->where('source', 2)->count();
        $tmt_number = self::query()->where('source', 3)->count();

        return [
            '文章总数' => $all_num,
            '虎嗅'   => $hx_number,
            '36氪'  => $k36_number,
            '钛媒体'  => $tmt_number,
        ];
    }
}
